package com.me.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.me.dao.AdminDAO;
import com.me.entity.Admin;

@Service("adminService")
public class AdminService extends BaseService<Admin, AdminDAO> {
	/**
	 * 注入DAO
	 */
	@Resource
	private AdminDAO adminDAO;

	/**
	 * 判断用户账号是否存在
	 */
	public boolean isExistAdmin(Admin admin){
		Assert.notNull(admin);
		if(admin.getAccount() == null || "".equals(admin.getAccount())){
			return false;
		}
		Admin temp = new Admin();
		temp.setAccount(admin.getAccount());
		if(adminDAO.preciseCount(temp) > 0){
			return true;
		}
		return false;
	}
	
	/**
	 * 校验用户名和密码是否正确
	 */
	public boolean checkLogin(Admin admin){
		Assert.notNull(admin);
		if(admin.getAccount() == null || "".equals(admin.getAccount())){
			return false;
		}
		if(admin.getPassword() == null || "".equals(admin.getPassword())){
			return false;
		}
		if(adminDAO.preciseCount(admin) > 0){
			return true;
		}
		return false;
	}
	
	/**
	 * 实现父类的抽象方法
	 */
	@Override
	protected AdminDAO getDao() {
		return adminDAO;
	}

}
